<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<base href="#(basePath)"/>
<title>商户后台</title>
</head>
<link href="build/bootstrap/css/font-awesome.min.css" rel="stylesheet" type="text/css">
<link href="build/bootstrap/css/bootstrap.min.css" rel="stylesheet" type="text/css">
<link href="build/bootstrap/css/bootstrap-theme.min.css" rel="stylesheet" type="text/css">
<link href="build/bootstrap/css/templatemo_style.css" rel="stylesheet" type="text/css">	
<script src="build/bootstrap/jquery-1.11.1.min.js" type="text/javascript"></script>
<script src="build/bootstrap/bootstrap.min.js" type="text/javascript"></script>
<script >
		document.onkeydown = function(event) {
			var event = document.all ? window.event : event;
			if ((event.keyCode || event.which) == 13) {
				$('#loginButton').click();
			 }
		}
		
		function login(){
			var userName = $("#userName").val();
			var password = $("#password").val();
			var captchaCode = $("#captchaCode").val();
			if(userName == ""){
				showError("请输入用户名");
			}else if(password == ""){
				showError("请输入密码")
			}else if(captchaCode == ""){
				showError("请输入验证码")
			}else{
				$.post("merch/login",{userName:userName,password:password,captchaCode:captchaCode},function(rsp){
					if(rsp.statusCode == "200"){
						window.location.href = "merch/user/index";
					}else{
						showError(rsp.message);
						if(rsp.message == '用户名/密码错误') {
							changeCode();
							$('#captchaCode').val("");
						}
					}
				});
			}
		}
		
        function changeCode() {
            var myImg = document.getElementById("captchaCodeImg");
            myImg.src="merch/getCaptchaCode?" + Math.random();
        }
        function showError(msg){
        	$("#alertMsg").html(msg);
        	$("#alertMsg").show();
        }
	</script>
<body class="templatemo-bg-gray">
 <div class="container">
		<div class="col-md-12">
			<h1 class="margin-bottom-15">商户后台</h1>
			<form class="form-horizontal templatemo-container templatemo-login-form-1 margin-bottom-30" role="form" action="merch/login" method="post">
				<div class="alert alert-danger" style="display: none;padding:6px;border-radius:0px;" id="alertMsg"></div>				
		        <div class="form-group">
		          <div class="col-xs-12">		            
		            <div class="control-wrapper">
		            	<label for="username" class="control-label fa-label"><i class="fa fa-user fa-medium"></i></label>
		            	<input type="text" class="form-control" name="userName" id="userName" placeholder="用户名">
		            </div>		            	            
		          </div>              
		        </div>
		        <div class="form-group">
		          <div class="col-md-12">
		          	<div class="control-wrapper">
		            	<label for="password" class="control-label fa-label"><i class="fa fa-lock fa-medium"></i></label>
		            	<input type="password" class="form-control" name="password" id="password" placeholder="密码">
		            </div>
		          </div>
		        </div>
		        <div class="form-group">
		          <div class="col-md-12">
		          	<div class="control-wrapper col-md-8" style="padding-right:0px;">
		            	<label for="password" class="control-label fa-label"><i class="fa fa-refresh"></i></label>
		            	<input type="text" class="form-control" name="captchaCode" id="captchaCode" placeholder="验证码" maxlength="4" style="display: inline;">
		            </div>
		            <div class="col-md-4" style="padding-right:0px;">
		            	<img onclick="changeCode();" src="merch/getCaptchaCode" id="captchaCodeImg"  width="100%" style="height:32px;cursor:pointer;border:1px solid #dedede"/>
		            </div>
		          </div>
		        </div>
		        <hr>
		        <div class="form-group">
		          <div class="col-md-12">
		          	<div class="control-wrapper">
		          		<input id="loginButton" type="button" onclick="login()" value="登录" class="btn btn-info">
		          	</div>
		          </div>
		        </div>
		      </form>
		</div>
	</div>
</body>
</html>